#include<bits/stdc++.h>
using namespace std;
long long sum,res;
int n,a[1000011];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("india.in","r",stdin);
	freopen("india.out","w",stdout);
	cin >> n;
	for(int i = 1;i <= n;i++)
		cin >> a[i];
	sort(a + 1,a + n + 1);
	sum = a[1];
	for(int i = 2;i <= n;i++)
	{
		res += (i - 1ll) * a[i] - sum;
		sum += a[i];
	}
	cout << res << "\n";
	return 0;
}